package com.yuandian.management.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuandian.api.management.entity.ConfSegmentResourceRelation;
import com.yuandian.management.mapper.ConfSegmentResourceRelationMapper;
import com.yuandian.management.service.ConfSegmentResourceRelationService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 网端与资源关系表-Service实现
 * @author zfsn
 * @date 2023-5-31
 */
@Service
public class ConfSegmentResourceRelationServiceImpl extends ServiceImpl<ConfSegmentResourceRelationMapper, ConfSegmentResourceRelation>
		implements ConfSegmentResourceRelationService {

	@Autowired
	private ConfSegmentResourceRelationMapper confSegmentResourceRelationMapper;

	/**
	 * 获取服务资源
	 *
	 * @param confSegmentResourceRelation
	 * @return 通用返回对象
	 */
	@Override
	public Page<Map<String,Object>> listPage(ConfSegmentResourceRelation confSegmentResourceRelation) {
		return confSegmentResourceRelationMapper.listPage(new Page<>(confSegmentResourceRelation.getPageNum(), confSegmentResourceRelation.getPageSize()), confSegmentResourceRelation);
	}

	/**
	 * 检查同系统中是否存在以编辑后的url为前缀的服务资源(子字符串)
	 *
	 * @param confSegmentResourceRelation
	 * @return
	 */
	@Override
	public List<ConfSegmentResourceRelation> checkPrefixUrlExsit(ConfSegmentResourceRelation confSegmentResourceRelation) {
		return confSegmentResourceRelationMapper.checkPrefixUrlExsit(confSegmentResourceRelation);
	}

	@Override
	public Long insertAndGetId(ConfSegmentResourceRelation csrVo) {
		ConfSegmentResourceRelation csr = new ConfSegmentResourceRelation();
		BeanUtils.copyProperties(csrVo, csr);
		// url类型
		csr.setType(1);
		Long id = confSegmentResourceRelationMapper.addAndGetId(csr);
		return id;
	}

	@Override
	public List<ConfSegmentResourceRelation> listData(ConfSegmentResourceRelation csrVo) {
		return confSegmentResourceRelationMapper.listData(csrVo);
	}

}